package com.wb.core08_常用类.obj;
import java.util.Objects;

/**
 * @author 黄衡熙
 * @version 1.0
 */
public class Person {
    private int age;
    private String name;


/*        @Override
   public boolean equals(Object obj) {
       // 判断当前参数的类型是否与当前对象类型一致
       if (obj.getClass() == Person.class) {
           // 如果一致,则将参数对象强制转换成当前对象的类型
           Person person = (Person) obj;
           // 当参数对象的所有属性的值与当前对象的所有属性的值完全一致时,表示两者是同一个对象
           return this.name.equals(person.getName()) && this.age == person.getAge();
       }
       // 如果不一致,直接返回false
       return false;
   }*/


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return age == person.age && Objects.equals(name, person.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Person() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
